var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');

var app = getApp();

Page({
  data: {
    footprintList: [],
    numList:[{id:0},{id:1},{id:2},{id:3},{id:4},{id:5}],
    isSign:false,
  },
  getFootprintList() {
    let that = this;
    let user_id = wx.getStorageSync('userId');
    let mdata={user_id:user_id};
    util.request(api.userSign,mdata).then(function (res) {
      if (res.errno === 0) {
        let hits = res.data.hits;
        let numList=that.data.numList;
        for (var i = 0; i < numList.length; i++) {
             numList[i].id+=Number(hits);
             if(i==0){
               numList[i].checked=true;
             }
        }
        if (res.data.get_rank != res.data.now_time){
          that.setData({
            isSign:true
          });
        }
        that.setData({
          footprintList: res.data,
          numList:numList,
        });
      }
    });
  },
  qiandao:function(){
    let that=this;
    let user_id = wx.getStorageSync('userId');
    let mdata={user_id:user_id};
    util.request(api.insertRank,mdata).then(function (res) {
      let rank = res.rank;
      that.data.footprintList.qiandao_ranks =parseInt(that.data.footprintList.qiandao_ranks)+parseInt(rank);
      if (res.errno === 0) {
        that.setData({
          isSign: false,
          footprintList: that.data.footprintList
        });
      }
    });
  },
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: "用户积分"
    })
    this.getFootprintList();
  },
  onReady: function () {

  },
  onShow: function () {

  },
  onHide: function () {
    // 页面隐藏

  },
  onUnload: function () {
    // 页面关闭
  },
  //按下事件开始  
  touchStart: function (e) {
    let that = this;
    that.setData({
      touch_start: e.timeStamp
    })
    console.log(e.timeStamp + '- touch-start')
  },
  //按下事件结束  
  touchEnd: function (e) {
    let that = this;
    that.setData({
      touch_end: e.timeStamp
    })
    console.log(e.timeStamp + '- touch-end')
  }, 
})